package com.jzr.task.job.shiyan;

import com.jzr.task.db1.mapper.MyPrimaryMapper;
import com.jzr.task.db1.mapper.TDeptMapper;
import com.jzr.task.db1.model.TDept;
import com.jzr.task.db2.mapper.ShiyanMapper;
import com.jzr.task.db2.model.ShiyanDept;
import com.jzr.task.job.BaseJob;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component("Shiyan.SyncDept")
public class ShiyanSyncDept extends BaseJob {
    @Autowired
    private ShiyanMapper shiyanMapper;

    @Autowired
    private MyPrimaryMapper primaryMapper;

    @Autowired
    private TDeptMapper deptMapper;

    @Override
    public void process() throws Exception {
        //同步科室
        List<ShiyanDept> list = shiyanMapper.getDeptList();
        for(ShiyanDept p : list){
            TDept dept = new TDept();
            BeanUtils.copyProperties(p,dept);
            dept.setUpdateTime(LocalDateTime.now());
            Integer id = primaryMapper.getDeptId(p.getCode());
            if(id == null){
                deptMapper.insert(dept);
            }else{
                dept.setId(id);
                deptMapper.updateById(dept);
            }
        }
    }
}